﻿using B.S.DataBase.MyProject.Domain;
using B.S.DataBase.MyProject.ErrorCode;
using B.S.DataBase.MyProject.Infrastructure.Interface;
using B.S.DataBase.MyWrite.API.Appicant.Command.MenuCommand;
using MediatR;

namespace B.S.DataBase.MyWrite.API.Appicant.CommandHandler.MenuCommandHandler
{
    public class MentDelCommandHandler : IRequestHandler<MentDelCommand, APIResult<object>>
    {
        private readonly IBaseRepository<MenuModel> baseRepository;

        public MentDelCommandHandler(IBaseRepository<MenuModel> baseRepository)
        {
            this.baseRepository = baseRepository;
        }

        public async Task<APIResult<object>> Handle(MentDelCommand request, CancellationToken cancellationToken)
        {
            APIResult<object> result = new APIResult<object>();
            var i=baseRepository.GetAll().Result.FirstOrDefault(x=>x.MenuId==request.MenuId);
            i.IsDeleted=true;
            var model=baseRepository.Update(i).Result;
            if (model > 0)
            {
                result.Msg = "删除成功";
                result.data = model;
            }
            else
            {
                result.Msg = "删除失败";
                result.data = model;
            }
            return await Task.FromResult(result);
        }
    }
}
